<?
require "include/bittorrent.php";
dbconn();
stdhead("Staff");
begin_main_frame();

//Get minimum online time
$dt = sqlesc(get_date_time(time()-600));

//Search user database for uploader and above and display in alphabetical order, from lowest to highest class
$res = query("SELECT id, username, class, last_access FROM users WHERE class >= " . UC_UPLOADER . " AND status='confirmed' ORDER BY class ASC, username") or sqlerr();

while ($arr = mysql_fetch_assoc($res))
{
	if ($col[$arr['class']] >= 3)
	{
		$staff[$arr['class']] .= "</tr>\n<tr height=25>";
		$col[$arr['class']]=0;
	}

	$staff[$arr['class']] .= "<td class=embedded>";
	$staff[$arr['class']] .= ($CURUSER ? "<a class=altlink href=userdetails.php?id=$arr[id]>" : "<font color=#A83838><b>");
	$staff[$arr['class']] .= $arr[username];
	if ($CURUSER)
	$staff[$arr['class']] .= "</a><sup><font color=#" . ("'" .$arr['last_access']. "'">=$dt?"008000>On":"8b0000>Off" ) . "line</font></sup>";
	else
	$staff[$arr['class']] .= "</b></font>";
	$staff[$arr['class']] .= "</td><td class=embedded>";
	$staff[$arr['class']] .= ($CURUSER ? "<a href=sendmessage.php?receiver=$arr[id]><img src=/pic/button_pm.gif alt=\"Send PM\" title=\"Send PM\" border=0></a>" : "");
	$staff[$arr['class']] .= "</td><td class=embedded><a href=mailto:$SITEEMAIL><img src=/pic/button_mail.gif alt=\"Send Email\" title=\"Send Email\" border=0 alt=$SITEEMAIL></a></td>";
	$col[$arr['class']]++;

	if ($col[$arr['class']] < 3)
	$staff[$arr['class']] .= "<td class=embedded>&nbsp;</td>";
}

//Output staff table
begin_frame("Staff");
print("<table width=725 cellspacing=0 align=center>\n");

$class = end($staff);
$classnum = key($staff);
print("<tr>");
print("<td class=embedded width='125'><b>" . get_user_class_name($classnum) . "</b></td>");
print("<td class=embedded width='25'>&nbsp;</td>");
print("<td class=embedded width='35'>&nbsp;</td>");
print("<td class=embedded width='85'>&nbsp;</td>");
print("<td class=embedded width='125'>&nbsp;</td>");
print("<td class=embedded width='25'>&nbsp;</td>");
print("<td class=embedded width='35'>&nbsp;</td>");
print("<td class=embedded width='85'>&nbsp;</td>");
print("<td class=embedded width='125'>&nbsp;</td>");
print("<td class=embedded width='25'>&nbsp;</td>");
print("<td class=embedded width='35'>&nbsp;</td>");
print("</tr>\n");
print("<tr><td class=embedded colspan=11><hr color='#000000' size=1></td></tr>\n");
print("<tr height=25>$class</tr>\n");
array_pop($staff);
while ($class = end($staff))
{
	$classnum = key($staff);
	print("<tr><td class=embedded colspan=11>&nbsp;</td></tr>\n");
	print("<tr><td class=embedded colspan=11><b>" . get_user_class_name($classnum) . "s</b></td></tr>\n");
	print("<tr><td class=embedded colspan=11><hr color='#000000' size=1></td></tr>\n");
	print("<tr height=25>$class</tr>\n");
	array_pop($staff);
}

print("</table>\n");
end_frame();

end_main_frame();
stdfoot();
?>